"""
@Author:WKVugen
@Time:2023-06-29
@Description:
"""
import datetime
import time
from utils.caiHong import CaiHongP
from selenium.webdriver.common.by import By
from base.base_page import BasePage
from pageobject.login_page import LoginPage


class AddDemandPage(BasePage):

    # 页面元素
    supplier_demand_loc = (By.XPATH, "//span[text()='供应商招募管理']")
    demand_manage_loc = (By.XPATH, "//span[text()='招募需求管理']")
    add_loc = (By.XPATH, "//span[text()='新增']")
    new_demand_name_loc = (By.XPATH, "//input[@placeholder='请输入需求名称']")
    new_demand_comment_loc = (By.XPATH, "//textarea[@placeholder='请输入需求描述']")
    publish_time_loc = (By.XPATH, "//input[@placeholder='选择发布时间']")
    time_ok_01_loc = (By.XPATH, "/html/body/div[2]/div[2]/button[2]/span")
    is_long_false_loc = (By.XPATH, "//*[@id='app']/div/div[2]/section/div/div[1]/div/form/div[1]/div[2]/div[4]/div[2]/div/label[2]")
    start_time_loc = (By.XPATH, "//input[@placeholder='选择招募开始时间']")
    time_ok_02_loc = (By.XPATH, "/html/body/div[3]/div[2]/button[2]/span")
    end_time_loc = (By.XPATH, "//input[@placeholder='选择招募结束时间']")
    time_ok_03_loc = (By.XPATH, "/html/body/div[4]/div[2]/button[2]/span")
    choose_mode_loc = (By.XPATH, "//input[@placeholder='请选择供应链模式']")
    mode_01_loc = (By.XPATH, "/html/body/div[5]/div[1]/div[1]/ul/li[1]/span")
    banner_loc = (By.XPATH, "//input[@type='file']")
    demand_info_loc = (By.XPATH, "//*[@id='app']/div/div[2]/section/div/div[1]/div/form/div[2]/div[2]/div/div[2]/div/div[2]/div[1]")
    upload_loc = (By.XPATH, "//*[@id='app']/div/div[2]/section/div/div[1]/div/div[3]/div[2]/div/form/div[3]/div/div/div/div[2]/div/div/div/input")

    # 页面动作
    def add_demand(self):
        # 登陆
        lg = LoginPage(self.driver)
        lg.login_demand()
        # 进入管理页面
        self.click(AddDemandPage.supplier_demand_loc)
        time.sleep(1)
        self.click(AddDemandPage.demand_manage_loc)
        time.sleep(3)
        self.click(AddDemandPage.add_loc)
        time.sleep(1)
        time_now = datetime.datetime.now()
        self.set_keys(AddDemandPage.new_demand_name_loc, f"测试新增招募需求{time_now.strftime('%m%d%H:%M:%S')}")
        p = CaiHongP()
        data = p.cai_hong_pi()
        demand_comment = data["result"]["content"]
        self.set_keys(AddDemandPage.new_demand_comment_loc, demand_comment)
        time_now_plus_one = time_now + datetime.timedelta(days=1)  # 加上1天
        self.set_keys(AddDemandPage.publish_time_loc, time_now_plus_one.strftime('%Y-%m-%d %H:%M:%S'))
        time.sleep(1)
        self.click(AddDemandPage.time_ok_01_loc)
        # 长期招募选择否
        self.click(AddDemandPage.is_long_false_loc)
        time_now_plus_tow = time_now + datetime.timedelta(days=2)
        self.set_keys(AddDemandPage.start_time_loc, time_now_plus_tow.strftime('%Y-%m-%d %H:%M:%S'))
        self.click(AddDemandPage.time_ok_02_loc)
        time_now_plus_3 = time_now + datetime.timedelta(days=3)
        self.set_keys(AddDemandPage.end_time_loc, time_now_plus_3.strftime('%Y-%m-%d %H:%M:%S'))
        self.click(AddDemandPage.time_ok_03_loc)
        time.sleep(1)
        self.click(AddDemandPage.choose_mode_loc)
        time.sleep(1)
        self.click(AddDemandPage.mode_01_loc)
        # 上传banner
        self.set_keys(AddDemandPage.banner_loc, "D:/upload/banner.png")
        self.set_keys(AddDemandPage.demand_info_loc, "测试自动化新增招募需求" + time_now.strftime('%Y-%m-%d %H:%M:%S'))
        self.set_keys((By.XPATH, "//input[@placeholder='请输入资质名称']"), "资质证明材料1")
        self.set_keys((By.XPATH, "//textarea[@placeholder='请输入资质描述']"), "资质描述111111111")
        self.set_keys((By.XPATH, "//input[@placeholder='请输入材料名称']"), "材料001")
        self.set_keys((By.XPATH, "//textarea[@placeholder='请输入材料要求描述']"), "cailiao描述111111111")
        self.click((By.XPATH, "//span[text()='上传']"))
        time.sleep(1)
        # 上传文件
        self.set_keys(AddDemandPage.upload_loc, "D:/upload/导入模板-经营类目.xlsx")
        time.sleep(1)
        self.click((By.XPATH, "//span[text()='确 定']"))
        time.sleep(1)
        self.click((By.XPATH, "//span[text()='保存']"))

